package com.cxhc.quartz.task;

import com.cxhc.common.constant.WechatConstants;
import com.cxhc.common.wechat.WechatUtils;
import com.cxhc.system.service.app.IConfigService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;


@Component("wechat")
public class WechatTask {

    @Resource
    private IConfigService configService;

    /**
     * 更新token
     */
    public void updateToken() {
        String appId = configService.selectValueByKey(WechatConstants.APP_ID);
        String secret = configService.selectValueByKey(WechatConstants.APP_SECRET);
        String token = WechatUtils.getToken(appId, secret);
        if (token != null && !token.isEmpty()) {
            // 更新
            configService.updateValueByKey(WechatConstants.APP_TOKEN, token);
        }
    }
}
